import Vue from 'vue'
import Vuex from 'vuex'

import test from './modules/test'

Vue.use(Vuex)

export const state = {//vuex状态值，类似于全局变量
  isShow: true,
  change: 0
}

export const mutations = {//通过该对象更改state中状态值的变化
  show(state) {
    state.isShow = true
  },
  hide(state) {
    state.isShow = false
  },
  changeNum(state, num) {
    state.change += num
  }
}

export const actions = {//通过该对象触发mutations中改变状态值的方法
  showValue(context) {
    context.commit('show')
  },
  hideValue(context) {
    context.commit('hide')
  },
  changeValue(context) {
    context.commit('changeNum')
  }
}

export const getters = {//监听state中状态值是否变化，如果过变化将改变后的状态值写入到store中
  listernShow(state) {
    return state.show
  },
  listernChange(state) {
    return state.change
  }
}

export default new Vuex.Store({
  modules: {
    test
  },
  state,
  getters,
  actions,
  mutations
})
